package cmd

import (
	"fmt"
	"os/exec"
)

func CmdExec(Cmd string) bool{
	cmd := exec.Command("/bin/bash", "-c", Cmd)
	//创建获取命令输出管道
	_, err := cmd.StdoutPipe()
	if err != nil {
		fmt.Printf("Error:can not obtain stdout pipe for command:%s\n", err)
		return false
	}
	//执行命令
	if err := cmd.Start(); err != nil {
		fmt.Println("Error:The command is err,", err)

		return false
	}
	if Stderr,_:=cmd.StderrPipe();Stderr!=nil{

		return false
	}
	//wait 方法会一直阻塞到其所属的命令完全运行结束为止
	if err := cmd.Wait(); err != nil {
		//fmt.Println("wait:", err.Error())

		return false
	}
	return true
}

